

#include "Public.h"

 
void Init_Timer3_Config(void)
{
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure ={0};  
//  TIM_OCInitTypeDef        TIM_OCInitStructure ={0};
//  GPIO_InitTypeDef  GPIO_InitStructure ={0};
  NVIC_InitTypeDef  NVIC_InitStructure ={0};

//  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB , ENABLE  ); 
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);//配置时钟
//  
//  //------- ch4---GPIOB Pin_1---------     
//   GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_1;   
//   
//   GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;    //设置为复用浮空输出
//   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
//   GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP ;  
//   GPIO_Init(GPIOB, &GPIO_InitStructure);  
//   
//  // GPIO_PinAFConfig(GPIOB, GPIO_PinSource0, GPIO_AF_2); 
//   GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_1);
//     
  // Time base configuration 
  TIM_TimeBaseStructure.TIM_Period        = 65000;//2400;//gc.u32Pwm_Period;   // 240=50us   //count max number 50000
  TIM_TimeBaseStructure.TIM_Prescaler     = 0;
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseStructure.TIM_CounterMode   = TIM_CounterMode_Up;
  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;;//重复寄存器，用于自动更新pwm占 
  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
  
  //-------通道设置---

//  TIM_OCInitStructure.TIM_OCMode      = TIM_OCMode_Timing;         // 配置为 TIMER 模式 
  
//  TIM_OCInitStructure.TIM_OCMode      = TIM_OCMode_PWM1;         // 配置为 PWM 模式 1  
//  
//  TIM_OCInitStructure.TIM_OCPolarity   = TIM_OCPolarity_High;     // 输出通道电平极性配置 
// // TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; 
//   
//  TIM_OCInitStructure.TIM_OCIdleState  = TIM_OCIdleState_Set;     // 输出通道空闲电平极性配置  TIM_OCIdleState_Reset
////  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; 
//      
//  TIM_OCInitStructure.TIM_OutputState  = TIM_OutputState_DISABLE;  // 输出使能   
//
//  TIM_OCInitStructure.TIM_Pulse        = 0;//gc.u32Pwm_duty;       // 初始占空比 0   
//  TIM_OC4Init(TIM3, &TIM_OCInitStructure );  //4通道
//
//
//  TIM_OC4PreloadConfig( TIM3, TIM_OCPreload_Enable);  //使能预装载寄存器 
//
//  TIM_ARRPreloadConfig( TIM3, ENABLE );                //使能TIMx在ARR上的预装载寄存器
  
 // TIM_SelectOutputTrigger(TIM3, TIM_TRGOSource_OC1Ref);//选择TIMx触发输出模式
   
  

  
//-----NVIC------------------------------  
   NVIC_InitStructure.NVIC_IRQChannel                = TIM3_IRQn; // 设置中断来源   TIM1_CC_IRQn;
   NVIC_InitStructure.NVIC_IRQChannelPriority        = 2;            // 设置子优先级
   NVIC_InitStructure.NVIC_IRQChannelCmd             = ENABLE;
   NVIC_Init(&NVIC_InitStructure);  

 //------------------------  
   TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
   TIM_ClearFlag(TIM3, TIM_FLAG_Update);//清除周期值得中断标志位
//   TIM_ClearFlag(TIM3, TIM_FLAG_CC4);//清除比较值的中断标志位
   
   TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);  //周期中断使能
//   TIM_ITConfig(TIM3, TIM_IT_CC4,ENABLE );     //占空比 比较的中断使能
   
   TIM_Cmd(TIM3, ENABLE);   // 使能计数器
   
  //  TIM_Cmd(TIM3,DISABLE);   // 使能计数器

}
 